home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 742 / alist / alist.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  3KB  |  150 lines

  1. /* Programm zum Ausgeben der Filelaenge eines Files */
  2.  
  3. /* Geschrieben auf einem Amiga von Andre Willms (01/1992) */
  4.  
  5.  
  6. #include <exec/types.h>
  7. #include <libraries/dos.h>
  8. #include <libraries/dosextens.h>
  9. #include <ctype.h>
  10. #include <math.h>
  11.  
  12. void *OpenLibrary();
  13.  
  14. struct DosBase *DosBase;
  15. struct FileLock *DupLock(),*Lock();
  16.  
  17.  
  18. long listfiles();
  19.  
  20. main(arganz,argfeld)
  21.  
  22. int arganz;
  23. char **argfeld;
  24.  
  25. {
  26. int chpos;
  27. char dirname[160];
  28.  
  29.   printf("\nAList V1.00 written 02/1992 by Andre Willms\n\n");
  30.  
  31.   if (!(arganz==2))
  32.     {
  33.       printf("Bad Arguments!\n\n");
  34.       printf("Usage : AList <Path>\n\n");
  35.     }
  36.   else
  37.     {
  38.       libopen();
  39.  
  40.         chpos=strlen(argfeld[1])-1;
  41.         if ((argfeld[1][chpos]==':')|(argfeld[1][chpos]=='/'))
  42.           strcpy(&dirname,argfeld[1]);
  43.         else
  44.           sprintf(&dirname,"%s/",argfeld[1]);
  45.  
  46.         listfiles(&dirname);
  47.  
  48.       libclose();
  49.  
  50.     }
  51. }
  52.  
  53. libopen()
  54. {
  55. if(!(DosBase= (struct DosBase *)
  56.      OpenLibrary("dos.library",0L)))
  57.   {
  58.     printf("Keine Dos-Library");
  59.     libclose();
  60.     exit(FALSE);
  61.   }
  62.  
  63. }
  64.  
  65. libclose()
  66. {
  67. if (DosBase) CloseLibrary(DosBase);
  68. }
  69.  
  70.  
  71.  
  72.  
  73. /* Funktion listet alle Files eines Directories  (incl. Sub-Dirs)*/
  74.  
  75. listfiles(name)
  76.  
  77. char *name;
  78.  
  79. {
  80. BOOL ok;
  81. struct FileLock *mylock;
  82. struct FileInfoBlock *myfib;
  83. UBYTE data[264];
  84. char newname[160],dirname[31];
  85. long laenge=0;
  86.  
  87.   myfib= (struct FileInfoBlock *) (((ULONG)(data) % 4) ? (data+2) : data);
  88.  
  89.   if(!(mylock=Lock(name,ACCESS_READ)))                /* Lock holen */
  90.     {
  91.       printf("ERROR while locking \"%s\". (Perhaps not existent.)\n\n",name);
  92.       libclose();
  93.       exit(FALSE);
  94.     }
  95.    else
  96.     {
  97.       if(!(ok=Examine(mylock,myfib)))                /* FIB holen */
  98.         {
  99.           printf("ERROR while getting FIB of \"%s\" !",name);
  100.         }
  101.       else
  102.         {
  103.           if(myfib->fib_DirEntryType<0)
  104.             {
  105.               printf("    %s\r\t\t\t\t%d \n",
  106.                       myfib->fib_FileName,myfib->fib_Size);
  107.               laenge+=myfib->fib_Size;
  108.             }
  109.           else
  110.             {
  111.               printf("\n%s\n",myfib->fib_FileName);
  112.               strcpy(&dirname,myfib->fib_FileName);
  113.  
  114.               while ((ok=ExNext(mylock,myfib)))
  115.                 {
  116.                   if (myfib->fib_DirEntryType<0)
  117.                     {
  118.                       printf("    %s\r\t\t\t\t%d \n",
  119.                               myfib->fib_FileName,myfib->fib_Size);
  120.                       laenge+=myfib->fib_Size;
  121.                     }
  122.                   else
  123.                     {
  124.                       sprintf(&newname,"%s%s/",name,myfib->fib_FileName);
  125.  
  126.                       laenge+=listfiles(&newname);    /* Rekursion */
  127.                     }
  128.  
  129.                 } /* while exnext */
  130.   
  131.               printf("-----------------------------------------------------------------------------\n");
  132.               printf("%s\r\t\t\t\t%d Bytes (%.1f KBytes, %.1f MBytes) \n\n",
  133.                       &dirname,laenge,(float)(laenge)/1024,
  134.                       (float)(laenge)/1024/1024);
  135.     
  136.             } /* else examine */
  137.  
  138.         } /* else direntrytype */
  139.  
  140.       UnLock(mylock);
  141.       
  142.     } /* else lock */
  143.  
  144.   return(laenge);
  145.  
  146. } /* listfiles */
  147.  
  148.  
  149.  
  150.